package cn.it.hbtt.web;

import cn.it.hbtt.entity.User;
import cn.it.hbtt.service.UserService;
import cn.it.hbtt.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username=request.getParameter("username");
        String pwd = request.getParameter("pwd");
        UserService userService = new UserServiceImpl();

        User user=new User();
        user.setUsername(username);
        user.setPwd(pwd);
        User loginUser=userService.login(user);

        if (loginUser!=null){
            request.getRequestDispatcher("/index.jsp").forward(request,response);
            return;
        }else {
            response.sendRedirect("Login.jsp");
        }

    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

    }
}
